import request from '@/utils/request';

/**
 * 创建基础 API 方法集合
 * @param {string} baseUrl - 基础路径
 * @param {string} baseApiName - API 名称前缀
 * @returns 通用 API 方法对象
 */
export function createBaseApi(baseUrl, baseApiName) {
	return {
		create(data) {
			return request({
				url: `${baseUrl}`,
				method: 'post',
				data,
				apiName: `${baseApiName}创建`
			})
		},
		update(data) {
			return request({
				url: `${baseUrl}`,
				method: 'post',
				data,
				apiName: `${baseApiName}修改`
			})
		},
		findAll(params) {
			return request({
				url: `${baseUrl}`,
				method: 'get',
				params,
				apiName: `${baseApiName}列表`
			})
		},
		findPage(params) {
			return request({
				url: `${baseUrl}/page`,
				method: 'get',
				params,
				apiName: `${baseApiName}分页列表`
			})
		},
		findOneById(id) {
			return request({
				url: `${baseUrl}/${id}`,
				method: 'get',
				apiName: `${baseApiName}更具id查询`
			})
		},
		remove(id) {
			return request({
				url: `${baseUrl}/${id}`,
				method: 'delete',
				apiName: `${baseApiName}删除`
			})
		},
		removeIds(id) {
			return request({
				url: `${baseUrl}/del/batch`,
				method: 'post',
				apiName: `${baseApiName}id批量删除`
			})
		}
	}
}